function [ CCBlocks,HARQ] = WiSiL_HARQ_ChaseCombining( blocks,HARQ )
% This function implements HARQ Chase Combining.
% The retransmited block LLR (blocks) is combined with the previous block LLR
% storaged in HARQ.CCBuffer
% accordingly to the acknowledgment vector HARQ.acknowledgement.
% History:
%
%   Lucas Sousa e Silva 08/2014 - created

CCBlocks = cell(size(blocks));                                              % Initialize the variable CCBlocks 

for k = 1:length(blocks)
    
    if (HARQ.acknowledgment(k))                                             
         CCBlocks{k} = HARQ.CCBuffer{k};                                    % Do not combine the LLR of previous retransmited blocks, beacause
    else                                                                    % the block has already been successfully decoded
        if(HARQ.repetitions(k) > 1)                                                  
            CCBlocks{k} = blocks{k} + HARQ.CCBuffer{k};                     % Combine the LLRs of previous retransmited blocks
        else
            CCBlocks{k} = blocks{k};                                        % If it is the first transmission, just pass on the LLR blocks
        end
    end
    
    HARQ.CCBuffer{k} = CCBlocks{k};                                         % Storage the current LLRs 
end

